<?php

//防止恶意调用
if (!defined('IN_MOD'))
{
    die('Hacking attempt');
}

/**
** THINKPHP and or 条件 使用说明

这里介绍thinkphp中两种条件and和or语句的写法

1、and条件的写法，它的写法比较简单
     $data[‘id’] = array(‘eq’,3);
     $data[‘pid’] = array(‘eq’,10);
     这句表达的意思是
     where id = 3 and pid = 10 这种写法

2、or条件的写法
  or条件的写法要分两种情况
  a、同一字段
     $data[‘id’] = array(array(‘eq’,3),array(‘eq’,10), ‘or’) ; 
     这句表达的意思是
     where id = 3 or id = 10 
  b、不同字段
     $where[‘name’]  = array(‘like’, ‘%aspbc.com%’);
     $where[‘title’]  = array(‘like’,’%aspbc.com%’);
     $where[‘_logic’] = ‘or’;
     $data[‘_complex’] = $where;   //or条件完成
     $data[‘id’]  = array(‘gt’,1); //其他条件
     这句表达的意思是
     where (name like ‘%aspbc.com%’ or title like ‘%aspbc.com%’) and id =1;
**/
if($configinfo['zdylistwhereconfig'] == 1)
{
	global $modulefilter;
	
	$search_wherename = $configinfo['search_where'];
	$search_filtername = $configinfo['search_filter'];
	
	// 表前缀
	$whereprefix = $configinfo['whereprefix'];
	
	$modulewhere = "";// 模块参数搜索条件
	
	// 搜索列表模型二 THINKPHP模式
	if($configinfo['listsearchmodulewhere'] == 2)
	{
		$modulewhere = array();// 模块参数搜索条件
	}
	
	$modulefilter = array();// 模块参数搜索组
	
	// 自定义列表搜索条件配置
	$getparametersearchname = getparametersearchname($configinfo['moduleid']);
	if($getparametersearchname)
	{
		foreach($getparametersearchname as $key=>$val)
		{
			// 搜索列表模型一
			if($configinfo['listsearchmodule'] == 1)
			{
				if($val['para'] == 'parameter_default')
				{
					if(moduleaqvarval('parameter_default_'.$val['field'],'string'))
					{
						$modulefilter['parameter_default_'.$val['field']] = $parameter_default[$val['field']] = moduleaqvarval('parameter_default_'.$val['field'],'string');
					}
				}
				if($val['para'] == 'parameter')
				{
					if(moduleaqvarval('parameter_'.$val['field'],'string'))
					{
						$modulefilter['parameter_'.$val['field']] = $parameter[$val['field']] = moduleaqvarval('parameter_'.$val['field'],'string');
					}
				}
			}
			
			// 搜索列表模型二
			if($configinfo['listsearchmodule'] == 2)
			{
				if($val['para'] == 'parameter_default')
				{
					if(moduleaqvarval('parameter_default['.$val['field'].']','string'))
					{
						$modulefilter['parameter_default['.$val['field'].']'] = $parameter_default[$val['field']] = moduleaqvarval('parameter_default['.$val['field'].']','string');
					}
				}
				if($val['para'] == 'parameter')
				{
					if(moduleaqvarval('parameter['.$val['field'].']','string'))
					{
						$modulefilter['parameter['.$val['field'].']'] = $parameter[$val['field']] = moduleaqvarval('parameter['.$val['field'].']','string');
					}
				}
			}
			
			// 搜索列表模型三
			if($configinfo['listsearchmodule'] == 3)
			{
				if($val['para'] == 'parameter_default')
				{
					if(moduleaqvarval(array('parameter_default',$val['field']),'string'))
					{
						$modulefilter['parameter_default'][$val['field']] = $parameter_default[$val['field']] = moduleaqvarval(array('parameter_default',$val['field']),'string');
					}
				}
				if($val['para'] == 'parameter')
				{
					if(moduleaqvarval(array('parameter',$val['field']),'string'))
					{
						$modulefilter['parameter'][$val['field']] = $parameter[$val['field']] = moduleaqvarval(array('parameter',$val['field']),'string');
					}
				}
			}
		}
		
		// 搜索列表模型一
		if($configinfo['listsearchmodulewhere'] == 1)
		{
			// parameter_default搜索
			$parametersearch = parametersearch($parameter_default,1,$whereprefix);
			if($parametersearch['where'])
			{
				$modulewhere .= $parametersearch['where'];
			}
			// parameter搜索
			$parametersearch = parametersearch($parameter,2,$whereprefix);
			if($parametersearch['where'])
			{
				$modulewhere .= $parametersearch['where'];
			}
		}
		
		// 搜索列表模型二 THINKPHP模式
		if($configinfo['listsearchmodulewhere'] == 2)
		{				
			// parameter_default搜索
			$parametersearch = parametersearch($parameter_default,1,$whereprefix,1);
			if($parametersearch['where'])
			{
				$modulewhere += $parametersearch['where'];
			}
			// parameter搜索
			$parametersearch = parametersearch($parameter,2,$whereprefix,1);
			if($parametersearch['where'])
			{
				$modulewhere += $parametersearch['where'];
			}
		}
	}
	
	// 自定义模块参数开启时
	if($configinfo['zdypara'] == 1)
	{
		// 搜索列表模型一
		if($configinfo['listsearchmodulewhere'] == 1)
		{
			$searchpara = getsearchparameterwhere2($whereprefix);
			$searchparawhere = $searchpara['where'];
			if($searchparawhere)$modulewhere .= $searchparawhere;
		}
		
		// 搜索列表模型二 THINKPHP模式
		if($configinfo['listsearchmodulewhere'] == 2)
		{
			$searchpara = getsearchparameterwhere2($whereprefix,1);
			$searchparawhere = $searchpara['where'];
			if($searchparawhere)$modulewhere += $searchparawhere;
		}
	}
	
	// 搜索条件组
	if(moduleaqvarval('attrid','intval'))$modulefilter['attrid']    = moduleaqvarval('attrid','intval');
	if($configinfo['lang'])$modulefilter['lang']    = $configinfo['lang'];
	if(moduleaqvarval('morepara','intval'))$modulefilter['morepara']    = moduleaqvarval('morepara','string');
	
	// 搜索列表模型一
	if($configinfo['listsearchmodulewhere'] == 1)
	{
		if(moduleaqvarval('attrid','intval'))$modulewhere .= " AND {$whereprefix}attrid = '".moduleaqvarval('attrid','intval')."'";// 关联信息
		if($configinfo['lang'])$modulewhere .= " AND {$whereprefix}lang = '".$configinfo['lang']."'";// 多语言	
		
		// 商家用户
		if($configinfo['supplier_id'])
		{
			$modulewhere .= getsupplierwhere(1,$whereprefix);
		}
		
		// 是否商家商品
		if($_MGPC_POST['supplierdata'])
		{
			if($_MGPC_POST['supplierdata'] == 1)
			{
				$modulewhere .= " AND {$whereprefix}supplier_id > 0";
			}else{
				$modulewhere .= " AND {$whereprefix}supplier_id = 0";
			}
		}
	}
	
	// 搜索列表模型二 THINKPHP模式
	if($configinfo['listsearchmodulewhere'] == 2)
	{
		if(moduleaqvarval('attrid','intval'))$modulewhere[$whereprefix.'attrid'] = array('EQ',moduleaqvarval('attrid','intval'));// 关联信息
		if($configinfo['lang'])$modulewhere[$whereprefix.'lang'] = array('EQ',$configinfo['lang']);// 多语言
		
		// 商家用户
		if($configinfo['supplier_id'])
		{
			$modulewhere += getsupplierwhere(2,$whereprefix);
		}
		
		// 是否商家商品
		if($_MGPC_POST['supplierdata'])
		{
			if($_MGPC_POST['supplierdata'] == 1)
			{
				$modulewhere[$whereprefix.'supplier_id'] = array('gt',0);
			}else{
				$modulewhere[$whereprefix.'supplier_id'] = array('EQ',0);
			}
		}
	}	
	
	// 搜索列表模型一
	if($configinfo['listsearchmodulewhere'] == 1)
	{
		@$$search_wherename .= $modulewhere;
	}
	// 搜索列表模型二 THINKPHP模式
	if($configinfo['listsearchmodulewhere'] == 2)
	{
		if(!isset($$search_wherename))$$search_wherename=array();
		$$search_wherename += $modulewhere;
	}
	// filter组
	if($configinfo['search_filter'])
	{
		if(!isset($$search_filtername))$$search_filtername=array();
		$$search_filtername += $modulefilter;
	}
}
?>